<template>
  <div>
    <div v-if="answer.finished && answer.items.length == 0" v-cloak>
        <div class="no-data aui-text-center aui-text-9">
            <i class="iconfont icon-lujing1161"></i>
            <div class="aui-ftn16">
                空空如也~
            </div>
        </div>
    </div>
    <div id="answer_answer">
      <van-pull-refresh v-model="answer.refreshing" @refresh="fnLoadMore" :disabled="disabled">
          <van-list
            v-model="answer.loading"
            :finished="answer.finished"
            :finished-text="text"
            @load="initData"
          >
          <div class="list aui-padded-10 aui-border-b aui-bg-f" v-for="(item, index) in answer.items" :key="index" @click="fnOpenAnswerDetail(item.qid)" v-cloak>
              <div class="title aui-ellipsis-2 aui-text-7 aui-ftn14 aui-font-weight" v-text="item.question"></div>
              <div class=" aui-padded-t-10">
                  <div class="aui-label aui-label-danger aui-margin-r-5" v-text="item.reward"></div>
                  <div class="aui-label aui-text-f" v-text="item.status"></div>
              </div>
              <van-row class="aui-padded-t-10">
                  <van-col span="16" class="aui-ftn12 aui-text-9">
                      买号{{item.buynum}}去找答案
                  </van-col>
                  <van-col span="8" class="aui-text-right aui-ftn12 aui-text-9" v-text="item.createtime">
                  </van-col>
              </van-row>
          </div>
        </van-list>
        </van-pull-refresh>
    </div>
  </div>
</template>

<script>
  import Answer from '../../../service/answer.js'
  export default {
    data () {
      return {
        text: '',
        answer: {
          loading: false,
          finished: false,
          refreshing: false,
          items: [],
          page: 0
        },
		disabled: false,
		loading: false
      }
    },
	mounted() {
		window.addEventListener('scroll', this.handleScroll, true)
	},
	beforeDestroy() {
		window.removeEventListener('scroll', this.handleScroll, true)
	},
    methods: {
		handleScroll () {
			this.disabled = this.utils.handleScroll()
		},
      initData: function() {
		  if (this.answer.loading && !this.answer.finished && !this.loading) {
		  	this.loading = true
		  	this.answer.page++
		  	Answer.fnGetRecord({p: this.answer.page, n: 20, uid: this.$store.state.uid,isToken: true, isLoading: true}).then(res => {
		  		this.loading = false
		  		// 加载状态结束
		  		this.answer.loading = false;
		  		if (res && res.status) {
		  			this.answer.items = this.answer.items.concat(res.data)
		  		} else {
		  			this.answer.finished = true;
		  			if (this.answer.items.length > 0) this.text = '没有更多了'
		  		}
		  	})
		  }
      },
      fnLoadMore: function() {
		this.text = ''
        this.answer.finished = false
        this.answer.loading = true
        this.answer.page = 0
		this.answer.refreshing = false;
		this.answer.items = []
        this.initData()
      },
      fnOpenAnswerDetail: function(id) {
        this.utils.fnOpenCommon(this, {name: 'answer_detail', params: {id: id}})
      }
    }

  }
</script>
